#include "main.h"

void deleteFile (char * fileNames[])
{
	fileHead ** list;
	FILE ** arc;
	char* arcnew;
	char * pos;
	char a[] = "XXXXXX";
	int m = 0;
	int i = 0;
	arcnew = (char * ) calloc (strlen(fileNames[0]) + 7,sizeof(char));
	envInf.tmpArcName = arcnew; 
	if (!arcnew)	cl_exit (DEL_FILE, MEMORY_ERR);
	strcat (arcnew,fileNames[0]);
	strcat (arcnew,a);
	arc = openArc (fileNames[0],arcnew);
	if (arc[0])	{
		if ((m = testing(arc[0])) == 1)	cl_exit (DEL_FILE,CS_ERR);
		m = 0;
		list = listingFile (arc[0]);
		while (list[m])	{
			i = 1;
			while (fileNames[i])	{
				pos = getName (fileNames[i]);
				if (!(strcmp(list[m]->fileName,pos)))	list[m]->rplFlag = DEL_FILE_FL;
				i++;
			}
			m++;
		}
		copyArc (arc,list);
		fclose (arc[0]);
		envInf.old_arc = NULL;
		fclose (arc[1]);
		envInf.new_arc = NULL;
		clean_files (fileNames[0],arcnew,NEW_ARC);
		free (arcnew);
		envInf.tmpArcName = NULL;
		m = 0;
		while (list[m])	{	
			free (list[m]->fileName);	
			m++;	
		}
		free (list);
	} else cl_exit (DEL_FILE, ERR_ARC_OPEN);
	return;
}